package com.example;

import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * Hello world!
 */
@SpringBootApplication
@RestController
public class RocektMQDemoApp {
    @Resource
    private RocketMQTemplate rocketMQTemplate;
    @Value("${demo.rocketmq.topic}")
    private String springTopic;

    public static void main(String[] args) {
        SpringApplication.run(RocektMQDemoApp.class, args);
    }

    @RequestMapping("push")
    @ResponseBody
    public String push() {
        SendResult result = rocketMQTemplate.syncSend(springTopic, "strign topic by java");
        return result.getMsgId() + " " + result.getSendStatus();
    }
}
